<template>
  <div>
    <el-drawer :visible.sync="addtaskVisible" direction="rtl" size="35%">
      <template slot="title">
        <div style="height: 36px; line-height: 36px" v-if="type != 'add'">
          <span>{{ $t("查看") }}</span>
          <!-- v-if="status == '3'" -->
          <div
            v-if="status == '3' || status == '4'"
            style="display: inline-block; margin-left: 12px"
          >
            <div
              style="display: inline-block"
              @click="taskHandle('pause')"
              class="serch-btn"
            >
              {{ progreeTitle }}
            </div>
            <div
              style="display: inline-block; margin-left: 8px"
              @click="taskHandle('stop')"
              class="btn-red"
            >
              {{ $t("终止") }}
            </div>
          </div>
          <div
            v-if="
              status == '1' || status == '2' || status == '3' || status == '4'
            "
          >
            <img
              @click="deleteTask"
              style="
                position: absolute;
                right: 55px;
                top: 30px;
                cursor: pointer;
              "
              src="../../../../assets/images/task/calDel.svg"
            />
          </div>
        </div>
        <div v-else>
          {{ title }}
        </div>
      </template>
      <el-form
        :model="drawerForm"
        ref="drawerRef"
        :rules="formRules"
        :inline="true"
      >
        <el-form-item :label="$t('选择模板') + '：'" prop="templateName">
          <el-select
            :disabled="type !== 'add'"
            v-model="drawerForm.templateName"
            filterable
            remote
            reserve-keyword
            clearable
            @focus="judgeList"
            :placeholder="$t('请输入关键词')"
          >
            <el-option
              v-for="item in templateList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
              @click.native="changeTemplate(item)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('任务名称') + '：'" prop="name">
          <el-input
            maxlength="50"
            :disabled="type !== 'add'"
            v-model="drawerForm.name"
            :placeholder="$t('自动生成请先选择模板')"
          ></el-input>
        </el-form-item>
        <el-form-item :label="$t('任务类型') + '：'" prop="tempType">
          <el-select
            :disabled="type !== 'add'"
            v-model="drawerForm.tempType"
            :placeholder="$t('请选择')"
            @change="changeType"
          >
            <el-option
              v-for="item in tempTypeData"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          :label="$t('启动时间') + '：'"
          prop="regularStartTime"
          v-if="
            drawerBooArr.find((item) => {
              return item.type == 'regular';
            }).bool
          "
          :rules="
            drawerBooArr.find((item) => {
              return item.type == 'regular';
            }).bool
              ? formRules.startTime
              : []
          "
        >
          <el-date-picker
            :disabled="type !== 'add'"
            v-model="drawerForm.regularStartTime"
            :picker-options="timePickerOption"
            type="datetime"
            :placeholder="$t('选择开始时间')"
            value-format="yyyy-MM-dd HH:mm:ss"
            style="width: 200px"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          prop="overTimeLength"
          v-if="
            drawerBooArr.find((item) => {
              return item.type == 'immediate';
            }).bool ||
            drawerBooArr.find((item) => {
              return item.type == 'regular';
            }).bool
          "
          :label="$t('超时时长')"
          :rules="
            drawerBooArr.find((item) => {
              return item.type == 'regular';
            }).bool
              ? formRules.overTimeLength
              : []
          "
        >
          <el-input
            :disabled="
              type !== 'add'
                ? true
                : drawerBooArr.find((item) => {
                    return item.type == 'immediate';
                  }).bool
                ? true
                : false
            "
            v-model="drawerForm.overTimeLength"
            autocomplete="off"
            style="width: 250px"
          ></el-input>
          <span style="color: #fff">{{ $t("分钟") }}</span>
        </el-form-item>
        <el-row
          v-if="
            drawerBooArr.find((item) => {
              return item.type == 'immediate';
            }).bool ||
            drawerBooArr.find((item) => {
              return item.type == 'regular';
            }).bool
          "
        >
          <el-col>
            <el-form-item
              style="margin-top: 0"
              prop="overTimeActionType"
              :label="$t('超时动作')"
              :rules="
                drawerBooArr.find((item) => {
                  return item.type == 'regular';
                }).bool
                  ? formRules.overTimeActionType
                  : []
              "
            >
              <el-select
                v-model="drawerForm.overTimeActionType"
                :placeholder="$t('请选择')"
                :disabled="
                  type !== 'add'
                    ? true
                    : drawerBooArr.find((item) => {
                        return item.type == 'immediate';
                      }).bool
                    ? true
                    : false
                "
              >
                <el-option
                  v-for="item in drawActionOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col
            :span="24"
            style="padding-left: 100px"
            v-if="drawerForm.overTimeActionType == '4'"
          >
            <el-form-item
              style="margin-top: 0"
              prop="stopPoint"
              :rules="
                drawerForm.overTimeActionType == '4' ? formRules.stopPoint : []
              "
            >
              <el-input
                :disabled="type !== 'add'"
                v-model="drawerForm.stopPoint"
                autocomplete="off"
                :placeholder="$t('请输入停靠点位置')"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item
          v-if="
            drawerBooArr.find((item) => {
              return item.type == 'immediate';
            }).bool ||
            drawerBooArr.find((item) => {
              return item.type == 'regular';
            }).bool
          "
          :label="$t('超期上限') + '：'"
          prop="agingTime"
          :rules="
            drawerBooArr.find((item) => {
              return item.type == 'immediate';
            }).bool ||
            drawerBooArr.find((item) => {
              return item.type == 'regular';
            }).bool
              ? formRules.agingTime
              : []
          "
        >
          <el-input-number
            :disabled="type !== 'add'"
            v-model="drawerForm.agingTime"
            controls-position="right"
            :step="0.5"
            :min="0"
            :max="7"
          ></el-input-number>
          <span style="color: #fff">{{ $t("天") }}</span>
        </el-form-item>
        <div
          class="draw-content-explain"
          v-if="
            drawerBooArr.find((item) => {
              return item.type == 'immediate';
            }).bool ||
            drawerBooArr.find((item) => {
              return item.type == 'regular';
            }).bool
          "
        >
          <div>
            {{
              $t(
                "超时时长从真实执行开始计时超出后将强制终止正在执行的任务不包含暂停时长"
              )
            }}
          </div>
          <div>
            {{ $t("超期上限从计划执行开始计时超出后将不再执行等待执行的任务") }}
          </div>
        </div>
        <div
          v-if="
            drawerBooArr.find((item) => {
              return item.type == 'cycle';
            }).bool
          "
        >
          <el-form-item
            v-if="false"
            :label="$t('周期类型')"
            prop="cycleType"
            :rules="
              drawerBooArr.find((item) => {
                return item.type == 'cycle';
              }).bool
                ? formRules.cycleType
                : []
            "
          >
            <el-radio-group
              v-model="drawerForm.cycleType"
              :disabled="type !== 'add'"
            >
              <el-radio label="1">{{ $t("定周期") }}</el-radio>
              <el-radio disabled label="2">{{ $t("不定周期") }}</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- 常规 周期 -->
          <template>
            <!-- 标题 -->
            <div class="cycle-config">
              <div>{{ $t("配置") }}</div>
              <div class="chang-btn">
                <div>{{ $t("常规") }}</div>
                <div>{{ $t("高级") }}</div>
              </div>
            </div>
            <div class="model">
              <div class="model-title">
                <div>{{ $t("生效时段") }}</div>
              </div>
              <div class="take-effect-time">
                <el-form-item
                  :label="$t('开始日期') + '：'"
                  :rules="
                    drawerBooArr.find((item) => {
                      return item.type == 'cycle';
                    }).bool
                      ? formRules.startTime
                      : []
                  "
                  prop="startTime"
                >
                  <el-date-picker
                    :disabled="type !== 'add'"
                    v-model="drawerForm.startTime"
                    type="date"
                    :placeholder="$t('选择日期')"
                    :picker-options="pickerOptionsStart"
                  >
                  </el-date-picker>
                </el-form-item>
                <el-form-item
                  :label="$t('结束日期') + '：'"
                  :rules="
                    drawerBooArr.find((item) => {
                      return item.type == 'cycle';
                    }).bool
                      ? formRules.endTime
                      : []
                  "
                  prop="endTime"
                >
                  <el-date-picker
                    :disabled="type !== 'add'"
                    v-model="drawerForm.endTime"
                    type="date"
                    :placeholder="$t('选择日期')"
                    :picker-options="pickerOptionsEnd"
                  >
                  </el-date-picker>
                </el-form-item>
              </div>
              <div class="model-title" style="padding-top: 20px">
                <div>{{ $t("执行配置") }}</div>
                <div class="take-effect-time" style="border-bottom: 0">
                  <!-- 启动时间 -->
                  <el-form-item :label="$t('启动时间') + '：'" required>
                    <el-row>
                      <el-col :span="10">
                        <el-input-number
                          :disabled="type !== 'add'"
                          v-model="drawerForm.executeTimePre"
                          controls-position="right"
                          :min="0"
                          :max="23"
                          style="width: 100px"
                        ></el-input-number>
                      </el-col>
                      <el-col :span="3">{{ $t("小时") }}</el-col>
                      <el-col :span="10">
                        <el-input-number
                          :disabled="type !== 'add'"
                          v-model="drawerForm.executeTimeNext"
                          controls-position="right"
                          :min="0"
                          :max="59"
                          style="width: 100px"
                        ></el-input-number>
                      </el-col>
                      <el-col :span="1">{{ $t("分") }}</el-col>
                    </el-row>
                  </el-form-item>
                  <!-- 重复频率 -->
                  <el-form-item :label="$t('重复频率') + '：'" required>
                    <el-row>
                      <el-col :span="3">{{ $t("每") }}</el-col>
                      <el-col :span="8">
                        <el-input-number
                          :disabled="type !== 'add'"
                          v-model="drawerForm.repeatRate"
                          controls-position="right"
                          :min="0.5"
                          :step="0.5"
                          style="width: 100px"
                        ></el-input-number>
                      </el-col>
                      <el-col :span="10">
                        <el-select
                          :disabled="type !== 'add'"
                          v-model="drawerForm.repeatRateUnit"
                          :placeholder="$t('请选择')"
                        >
                          <el-option :label="$t('小时')" value="2"></el-option>
                          <el-option :label="$t('天')" value="3"></el-option>
                        </el-select>
                      </el-col>
                    </el-row>
                  </el-form-item>
                  <!-- 超时时长 -->
                  <el-form-item :label="$t('超时时长')" required>
                    <el-row style="display: flex">
                      <el-col :span="18" :xs="24">
                        <el-input-number
                          :disabled="type !== 'add'"
                          v-model="drawerForm.overTimeLength"
                          controls-position="right"
                          :min="1"
                          style="width: 100px"
                        ></el-input-number>
                      </el-col>
                      <label>{{ $t("分钟") }}</label>
                    </el-row>
                  </el-form-item>
                  <!-- 超时动作 -->
                  <el-form-item :label="$t('超时动作')" required>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-select
                          :disabled="type !== 'add'"
                          v-model="drawerForm.overTimeActionType"
                          :placeholder="$t('请选择')"
                          style="width: 208px"
                        >
                          <el-option
                            :label="$t('原地待命')"
                            value="1"
                          ></el-option>
                          <el-option
                            :label="$t('回充电桩')"
                            value="2"
                          ></el-option>
                          <!-- <el-option label="回到起点" value="3"></el-option> -->
                          <el-option
                            :label="$t('前往停靠点')"
                            value="4"
                          ></el-option>
                        </el-select>
                      </el-col>
                      <el-col
                        :span="24"
                        v-if="drawerForm.overTimeActionType == '4'"
                        style="padding-left: 10px"
                      >
                        <el-form-item
                          prop="stopPoint"
                          :rules="
                            drawerForm.overTimeActionType == '4'
                              ? formRules.stopPoint
                              : []
                          "
                        >
                          <el-input
                            :disabled="type !== 'add'"
                            v-model="drawerForm.stopPoint"
                            autocomplete="off"
                            :placeholder="$t('请输入停靠点位置')"
                            clearable
                          ></el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form-item>
                  <el-form-item :label="$t('超期上限') + '：'" required>
                    <el-col :span="22">
                      <el-input-number
                        :disabled="type !== 'add'"
                        v-model="drawerForm.agingTime"
                        controls-position="right"
                        :min="0"
                        :max="7"
                        :step="0.5"
                        style="width: 100px"
                      ></el-input-number>
                    </el-col>
                    <el-col :span="2">{{ $t("天") }}</el-col>
                  </el-form-item>
                </div>
                <div
                  class="draw-content-explain"
                  v-if="
                    drawerBooArr.find((item) => {
                      return item.type == 'cycle';
                    }).bool
                  "
                >
                  <div>
                    {{
                      $t(
                        "超时时长从真实执行开始计时超出后将强制终止正在执行的任务不包含暂停时长"
                      )
                    }}
                  </div>
                  <div>
                    {{
                      $t(
                        "超期上限从计划执行开始计时超出后将不再执行等待执行的任务"
                      )
                    }}
                  </div>
                </div>
              </div>
            </div>
          </template>
          <!-- 高级 周期 -->
          <template v-if="false">
            <!-- 生效时段 -->
            <div class="model">
              <div class="model-title">
                <div>{{ $t("生效时段") }}</div>
              </div>
              <el-form-item
                :label="$t('生效时长')"
                prop="validType"
                :rules="
                  drawerBooArr.find((item) => {
                    return item.type == 'cycle';
                  }).bool
                    ? formRules.validType
                    : []
                "
              >
                <el-radio-group
                  v-model="drawerForm.validType"
                  :disabled="type !== 'add'"
                >
                  <el-radio label="1">{{ $t("永久生效") }}</el-radio>
                  <el-radio label="2">{{ $t("指定时段") }}</el-radio>
                </el-radio-group>
              </el-form-item>
              <!-- 快速设置 -->
              <div v-if="drawerForm.validType == '2'">
                <div class="hurry-setting">
                  <div class="title" style="padding-left: 20px">
                    {{ $t("快速设置") }}
                  </div>
                  <div
                    v-for="(item, index) in hurrySetting"
                    :key="index"
                    :class="[
                      'contents',
                      index == currentSetting ? 'current' : '',
                    ]"
                    @click="chooseQuickSetting(index)"
                  >
                    <div class="cursor-pointer">{{ item.label }}</div>
                  </div>
                </div>
                <!-- 快速设置 开始时间 -->
                <el-form-item
                  prop="quickStartDate"
                  :label="$t('开始时间') + '：'"
                  style="display: flex"
                  :rules="
                    drawerBooArr.find((item) => {
                      return item.type == 'cycle';
                    }).bool && drawerForm.validType == '2'
                      ? formRules.quickStartDate
                      : []
                  "
                >
                  <el-date-picker
                    :disabled="type !== 'add'"
                    v-model="drawerForm.quickStartDate"
                    type="datetime"
                    :placeholder="$t('选择开始时间')"
                  >
                  </el-date-picker>
                </el-form-item>
                <!-- 快速设置  结束时间-->
                <el-form-item
                  prop="quickEndDate"
                  :label="$t('结束时间') + '：'"
                  style="display: flex"
                  :rules="
                    drawerBooArr.find((item) => {
                      return item.type == 'cycle';
                    }).bool && drawerForm.validType == '2'
                      ? formRules.quickEndDate
                      : []
                  "
                >
                  <el-date-picker
                    :disabled="type !== 'add'"
                    v-model="drawerForm.quickEndDate"
                    type="datetime"
                    :placeholder="$t('选择结束时间')"
                  >
                  </el-date-picker>
                </el-form-item>
              </div>
            </div>
            <!-- 执行配置 -->
            <div class="config">
              <div class="model-title">{{ $t("执行配置") }}</div>
              <el-row>
                <!-- 重复频率 -->
                <el-form-item
                  :label="$t('重复频率')"
                  prop="repeatRate"
                  :rules="
                    drawerBooArr.find((item) => {
                      return item.type == 'cycle';
                    }).bool
                      ? formRules.repeatRate
                      : []
                  "
                >
                  <el-col :span="10">
                    <label>{{ $t("每") }}&nbsp;&nbsp;</label>
                    <el-input-number
                      :disabled="type !== 'add'"
                      v-model="drawerForm.repeatRate"
                      controls-position="right"
                      :min="0.5"
                      :step="0.5"
                      style="width: 100px"
                    ></el-input-number>
                  </el-col>
                  <el-col :span="14">
                    <el-select
                      :disabled="type !== 'add'"
                      v-model="drawerForm.repeatRateUnit"
                      :placeholder="$t('请选择')"
                      @change="repeatRateUnitChange"
                    >
                      <el-option
                        v-for="dict in dict.type.repeatRateUnit"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      >
                      </el-option>
                    </el-select>
                  </el-col>
                </el-form-item>
              </el-row>
              <el-row>
                <!-- 执行时间 -->
                <el-form-item :label="$t('执行时间') + '：'" required>
                  <!-- 月 -->
                  <el-row
                    class="month-time"
                    v-if="drawerForm.repeatRateUnit == '6'"
                  >
                    <label>{{ $t("月") }}</label>
                    <div
                      v-for="(item, index) in monthsData"
                      :key="index"
                      :class="['months', item.isSelected ? 'Active' : '']"
                      @click="monthClick(index, item)"
                    >
                      <div>{{ item.label }}</div>
                    </div>
                  </el-row>
                  <!-- 周 -->
                  <el-row
                    v-if="
                      drawerForm.repeatRateUnit == '4' ||
                      drawerForm.repeatRateUnit == '5' ||
                      drawerForm.repeatRateUnit == '6'
                    "
                    class="month-time"
                    style="margin: 15px 0"
                  >
                    <label>{{ $t("周") }}</label>
                    <div
                      v-for="(item, index) in weekData"
                      :key="index"
                      :class="['months', item.isSelected ? 'Active' : '']"
                      @click="weekClick(index, item)"
                    >
                      <div>{{ item.label }}</div>
                    </div>
                  </el-row>
                  <el-row class="month-time">
                    <label>{{ $t("秒") }}</label>
                    <div class="execute-time">
                      <el-form-item
                        prop="h"
                        v-if="
                          drawerForm.repeatRateUnit !== '1' &&
                          drawerForm.repeatRateUnit !== '2'
                        "
                        :rules="
                          drawerBooArr.find((item) => {
                            return item.type == 'cycle';
                          }).bool &&
                          drawerForm.repeatRateUnit !== '1' &&
                          drawerForm.repeatRateUnit !== '2'
                            ? formRules.h
                            : []
                        "
                      >
                        <el-input-number
                          :disabled="type !== 'add'"
                          v-model="drawerForm.h"
                          controls-position="right"
                          :min="1"
                          :max="12"
                          style="width: 80px"
                        ></el-input-number>
                        <span>{{ $t("小时") }}</span>
                      </el-form-item>
                      <el-form-item
                        prop="m"
                        v-if="drawerForm.repeatRateUnit !== '1'"
                        :rules="
                          drawerBooArr.find((item) => {
                            return item.type == 'cycle';
                          }).bool && drawerForm.repeatRateUnit !== '1'
                            ? formRules.m
                            : []
                        "
                      >
                        <el-input-number
                          :disabled="type !== 'add'"
                          v-model="drawerForm.m"
                          controls-position="right"
                          :min="1"
                          :max="60"
                          style="width: 80px"
                        ></el-input-number>
                        <span>{{ $t("分") }}</span>
                      </el-form-item>
                      <el-form-item
                        prop="s"
                        :rules="
                          drawerBooArr.find((item) => {
                            return item.type == 'cycle';
                          }).bool
                            ? formRules.s
                            : []
                        "
                      >
                        <el-input-number
                          :disabled="type !== 'add'"
                          v-model="drawerForm.s"
                          controls-position="right"
                          :min="1"
                          :max="60"
                          style="width: 80px"
                        ></el-input-number>
                        <span>{{ $t("秒") }}</span>
                      </el-form-item>
                    </div>
                  </el-row>
                </el-form-item>
                <!-- 超期上限 -->
                <el-form-item :label="$t('超期上限') + '：'" prop="agingTime">
                  <el-input-number
                    :disabled="type !== 'add'"
                    v-model="drawerForm.agingTime"
                    controls-position="right"
                    :step="0.5"
                    :min="0"
                    :max="7"
                  ></el-input-number>
                  <span>{{ $t("天") }}</span>
                </el-form-item>
              </el-row>
            </div>
          </template>
          <!-- 算法样本 -->
          <!-- <div class="algorith">
            <div class="model-title">{{ $t("算法训练样本") }}</div>
            <el-form-item
              :label="$t('是否采集训练样本')"
              label-width="273px"
              prop="trainingSampleGather"
              :rules="
                drawerBooArr.find((item) => {
                  return item.type == 'cycle';
                }).bool
                  ? formRules.trainingSampleGather
                  : []
              "
            >
              <el-radio-group
                v-model="drawerForm.trainingSampleGather"
                :disabled="type !== 'add'"
              >
                <el-radio label="1">{{ $t("不采集") }}</el-radio>
                <el-radio label="2">{{ $t("采集") }}</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item
              v-if="drawerForm.trainingSampleGather == '2'"
              :label="$t('云台单向转动次数')"
              label-width="240px"
              prop="trainingSampleCount"
              :rules="
                drawerBooArr.find((item) => {
                  return item.type == 'cycle';
                }).bool && drawerForm.trainingSampleGather == '2'
                  ? formRules.trainingSampleCount
                  : []
              "
            >
              <el-select
                :disabled="type !== 'add'"
                v-model="drawerForm.trainingSampleCount"
                :placeholder="$t('请选择')"
                style="width: 136px"
              >
                <el-option
                  v-for="item in trainingSampleCountList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <label>{{ $t("次") }}</label>
            </el-form-item>
            <el-form-item
              v-if="drawerForm.trainingSampleGather == '2'"
              :label="$t('云台转动角度间隔')"
              label-width="240px"
              prop="trainingSampleAngle"
              :rules="
                drawerBooArr.find((item) => {
                  return item.type == 'cycle';
                }).bool && drawerForm.trainingSampleGather == '2'
                  ? formRules.trainingSampleAngle
                  : []
              "
            >
              <el-select
                :disabled="type !== 'add'"
                v-model="drawerForm.trainingSampleAngle"
                :placeholder="$t('请选择')"
                style="width: 136px"
              >
                <el-option
                  v-for="item in trainingSampleAngleList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <label>°</label>
            </el-form-item>
          </div> -->
        </div>
      </el-form>
      <div v-if="type == 'add'" class="demo-drawer__footer drawer-footer">
        <div
          @click="submitBtn"
          class="serch-btn2"
          style="
            padding: 10px;
            display: flex;
            justify-content: center;
            align-items: center;
          "
        >
          {{
            drawerForm.tempType == $t("即时任务")
              ? $t("保存并立即执行")
              : $t("保存")
          }}
        </div>
        <div @click="drawerCancle" class="reset-btn">{{ $t("取消") }}</div>
      </div>
    </el-drawer>
    <!-- 立即执行弹框 -->
    <TaskDialog
      :taskDialog="taskVisible"
      :taskName="taskName"
      @taskDialogConfirm="dialogConfirm"
      @taskDialogCancle="taskDialogCancle"
    ></TaskDialog>
    <!-- 删除单日任务弹框 -->
    <TaskDeleteModal
      :detailInfos="detailInfos"
      :status="status"
      :taskId="taskId"
      :execId="execId"
      :rowTaskId="rowTaskId"
      @getDataList="getDataListEmit"
      @closeTaskModal="closeTaskModal"
      ref="task_delete_modal"
    ></TaskDeleteModal>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import {
  API_taskControl, //任务控制
  API_nextTaskInfo, //下一个任务信息
} from "@/api/robot/monitor";
import {
  API_immediate,
  API_regular,
  API_periodic,
  API_TemplateList,
} from "@/api/task/template";
import { API_GetTaskDetail } from "@/api/task/manage";
import moment from "moment";
import TaskDialog from "@/components/TaskDialog";
import TaskDeleteModal from "@/components/TaskDeleteModal";

export default {
  dicts: ["viewType", "overType", "dimension", "repeatRateUnit"],
  components: {
    TaskDialog,
    TaskDeleteModal,
  },
  data() {
    var stopPoint = (rule, value, callback) => {
      if (!value) {
        callback(new Error(this.$t("请输入正确格式数据")));
      } else {
        //轨道
        if (this.globalRobotInfo.moveMotor == "1") {
          var pattern = /^\d+.?\d{0,2}$/;
          if (!pattern.test(value)) {
            callback(new Error(this.$t("小数点后最多只能输入两位")));
          } else {
            callback();
          }
        } else {
          // 轮式
          let oribrule = /^\d+$/;
          // 截取前两个并判断
          let start = value.slice(0, 2);
          let num = value.slice(2);
          if (start != "LM") {
            callback(new Error(this.$t("轮式地图停靠位置请以LM开头")));
          } else if (!oribrule.test(num)) {
            callback(new Error(this.$t("请输入正确的格式")));
          } else {
            callback();
          }
        }
      }
    };
    return {
      //超时动作数组
      drawActionOptions: [],
      //定期执行限制
      timePickerOption: {
        disabledDate(time) {
          const dateTime = new Date();
          const startDateTime = dateTime.setDate(dateTime.getDate() - 1);
          return time.getTime() < new Date(startDateTime).getTime();
        },
      },
      pickerOptionsStart: {
        disabledDate: (time) => {
          let endDateVal = this.listQuery.endTime;
          if (endDateVal) {
            return (
              time.getTime() >=
              new Date(endDateVal).getTime() + 1 * 24 * 60 * 60 * 1000
            );
          }
        },
      },
      pickerOptionsEnd: {
        disabledDate: (time) => {
          let beginDateVal = this.listQuery.startTime;
          if (beginDateVal) {
            return time.getTime() < new Date(beginDateVal).getTime();
          }
        },
      },
      listQuery: {
        name: null,
        viewType: "",
        overType: "",
        dimension: "",
        priorityList: [],
        pageNum: 1,
        pageSize: 10,
      },
      drawerForm: {
        name: "",
        templateName: "", //模板名称
        tempType: this.$t("即时任务"), //任务类型
        stopPoint: "", //停靠点
        agingTime: 0, //超期上限
        regularStartTime: "", //定期执行启动时间
        cycleType: "1",
        validType: "2", //生效时长
        hurrySetting: "", //快速设置
        quickStartDate: "", //快速设置-开始日期
        quickEndDate: "", //快速设置-结束日期
        // 执行配置
        repeatRate: "3", //重复频率
        repeatRateUnit: "2", //重复频率单位
        //执行时间
        month: "", //循环monthsData获取isSelet为true
        week: "", //同上
        seconds: "",
        h: "",
        m: "",
        s: "",
        trainingSampleGather: "1", //是否采集训练样本
        trainingSampleCount: "", //云台转动次数
        trainingSampleAngle: "", //云台转动间隔
        //常规  生效时段
        startTime: "", //开始日期
        endTime: "", //结束日期
        overTimeLength: "", //超时时长
        overTimeActionType: "", //超时动作
        executeTimePre: 8, //启动时间 前
        executeTimeNext: 0, //启动时间 后
      },
      //快速设置数组
      hurrySetting: [
        {
          value: "1",
          label: this.$t("本月"),
        },
        {
          value: "2",
          label: this.$t("本季度"),
        },
        {
          value: "3",
          label: this.$t("本年"),
        },
        {
          value: "4",
          label: this.$t("未来30天"),
        },
        {
          value: "5",
          label: this.$t("未来90天"),
        },
        {
          value: "6",
          label: this.$t("未来365天"),
        },
      ],
      currentSetting: "",
      //弹框内部数据
      drawerBooArr: [
        {
          bool: false,
          type: "immediate",
        },
        {
          bool: false,
          type: "regular",
        },
        {
          bool: false,
          type: "cycle",
        },
      ],
      formRules: {
        name: [
          {
            required: true,
            message: this.$t("任务名称不能为空"),
            trigger: "blur",
          },
        ],
        templateName: [
          { required: true, message: this.$t("模板不能为空"), trigger: "blur" },
        ],
        overTimeLength: [
          {
            required: true,
            message: this.$t("超时时长不能为空"),
            trigger: "change",
          },
        ],
        overTimeActionType: [
          {
            required: true,
            message: this.$t("超时动作不能为空"),
            trigger: "change",
          },
        ],
        stopPoint: [{ required: true, validator: stopPoint, trigger: "blur" }],
        agingTime: [
          {
            required: true,
            message: this.$t("超时上限不能为空"),
            trigger: "blur",
          },
        ],
        regularStartTime: [
          {
            required: true,
            message: this.$t("开始时间不能为空"),
            trigger: "blur",
          },
        ],
        cycleType: [
          { required: true, message: this.$t("周期类型"), trigger: "blur" },
        ],
        validType: [
          {
            required: true,
            message: this.$t("请选择生效时长"),
            trigger: "change",
          },
        ],
        quickStartDate: [
          {
            required: true,
            message: this.$t("开始时间不能为空"),
            trigger: "change",
          },
        ],
        quickEndDate: [
          {
            required: true,
            message: this.$t("结束时间不能为空"),
            trigger: "change",
          },
        ],
        // 重复频率
        repeatRate: [
          {
            required: true,
            message: this.$t("重复频率不能为空"),
            trigger: "blur",
          },
        ],
        s: [
          { required: true, message: this.$t("秒数不能为空"), trigger: "blur" },
        ],
        m: [
          { required: true, message: this.$t("分钟不能为空"), trigger: "blur" },
        ],
        h: [
          { required: true, message: this.$t("小时不能为空"), trigger: "blur" },
        ],
        trainingSampleGather: [
          {
            required: true,
            message: this.$t("训练样本不能为空"),
            trigger: "blur",
          },
        ],
        trainingSampleCount: [
          {
            required: true,
            message: this.$t("云台单向转动次数不能为空"),
            trigger: "change",
          },
        ],
        trainingSampleAngle: [
          {
            required: true,
            message: this.$t("云台单向转动次数不能为空"),
            trigger: "change",
          },
        ],
        startTime: [
          {
            required: true,
            message: this.$t("开始日期不能为空"),
            trigger: "change",
          },
        ],
        endTime: [
          {
            required: true,
            message: this.$t("结束日期不能为空"),
            trigger: "change",
          },
        ],
      },
      templateData: [
        {
          value: "1",
          label: "模板1",
        },
      ],
      tempTypeData: [
        {
          value: "immediate",
          label: this.$t("即时任务"),
        },
        {
          value: "regular",
          label: this.$t("定期任务"),
        },
        {
          value: "cycle",
          label: this.$t("周期任务"),
        },
      ],
      actionData: [
        {
          value: "1",
          label: "动作1",
        },
      ],
      //执行配置--月
      monthsData: [
        {
          label: "1",
          isSelected: false,
        },
        {
          label: "2",
          isSelected: false,
        },
        {
          label: "3",
          isSelected: false,
        },
        {
          label: "4",
          isSelected: false,
        },
        {
          label: "5",
          isSelected: false,
        },
        {
          label: "6",
          isSelected: false,
        },
        {
          label: "7",
          isSelected: false,
        },
        {
          label: "8",
          isSelected: false,
        },
        {
          label: "9",
          isSelected: false,
        },
        {
          label: "10",
          isSelected: false,
        },
        {
          label: "11",
          isSelected: false,
        },
        {
          label: "12",
          isSelected: false,
        },
      ],
      //执行配置--周
      weekData: [
        {
          label: this.$t("一"),
          isSelected: false,
        },
        {
          label: this.$t("二"),
          isSelected: false,
        },
        {
          label: this.$t("三"),
          isSelected: false,
        },
        {
          label: this.$t("四"),
          isSelected: false,
        },
        {
          label: this.$t("五"),
          isSelected: false,
        },
        {
          label: this.$t("六"),
          isSelected: false,
        },
        {
          label: this.$t("七"),
          isSelected: false,
        },
      ],
      monthActive: "", //多选的月份
      weekActive: "", //多选的周
      // 云台转动次数
      trainingSampleCountList: [
        {
          label: "1",
          value: "1",
        },
        {
          label: "2",
          value: "2",
        },
        {
          label: "3",
          value: "3",
        },
        {
          label: "4",
          value: "4",
        },
        {
          label: "5",
          value: "5",
        },
      ],
      // 转动角度间隔
      trainingSampleAngleList: [
        {
          label: "0.1",
          value: "0.1",
        },
        {
          label: "0.2",
          value: "0.2",
        },
        {
          label: "0.3",
          value: "0.3",
        },
        {
          label: "0.4",
          value: "0.4",
        },
        {
          label: "0.5",
          value: "0.5",
        },
      ],
      addtaskVisible: false,
      taskVisible: false, //任务dialog
      taskName: "", //全局当前任务名称
      type: "add", //新增或查看
      title: "",
      detailInfos: {},
      templateList: [], //模板数据
      templateId: "",
      status: "",
      progreeTitle: "", //暂停 恢复暂停标题
      taskId: "", //任务id
      execId: "", //任务执行id
      currentTaskTimer: null, //当前任务定时器
      taskExecId: "",
      rowTaskId: "", //点击单日时的任务id
    };
  },
  props: {},
  computed: {
    ...mapGetters(["globalCurrentTaskInfo", "globalRobotInfo"]),
  },
  watch: {
    status: {
      handler(val) {
        if (val == "4") {
          this.$set(this, "progreeTitle", this.$t("暂停恢复"));
        } else {
          this.$set(this, "progreeTitle", this.$t("暂停"));
        }
      },
      immediate: true,
    },
  },
  mounted() {},
  methods: {
    getDataListEmit() {
      this.$emit("getDataList");
    },
    //删除单个子任务
    deleteTask() {
      this.$refs.task_delete_modal.open(this.taskExecId);
    },
    //判断有无任务模板
    judgeList() {
      if (this.templateList.length <= 0) {
        this.$message({
          type: "warning",
          message: this.$t("暂无任务模板请先创建任务模板"),
        });
      }
    },
    //获取当前任务信息
    getTaskInfo() {
      this.$store.dispatch("getGlobalTaskInfo").then((res) => {
        if (res.code == 200 && res.data) {
          this.taskId = JSON.parse(res.data).taskId; //任务ID
          this.execId = JSON.parse(res.data).execId; //任务执行ID
          this.taskName = JSON.parse(res.data).taskName; //任务名称
        }
      });
    },
    /**暂停 终止*/
    taskHandle(type) {
      switch (type) {
        case "pause":
          // 暂停
          if (this.status == "4") {
            //暂停恢复  //判断是否有任务正在执行
            if (this.taskId != -1) {
              this.$confirm(
                `${this.$t("当前正在执行：")}${
                  this.drawerForm.name
                }，暂不支持恢复其它任务。`,
                this.$t("提示"),
                {
                  showConfirmButton: false,
                  cancelButtonText: this.$t("取消"),
                  type: "warning",
                }
              )
                .then(() => {})
                .catch(() => {
                  this.$message({
                    type: "info",
                    message: this.$t("已取消"),
                  });
                });
            } else {
              this.$confirm(
                `${this.$t("确定恢复任务")}${this.drawerForm.name}?`,
                this.$t("提示"),
                {
                  confirmButtonText: this.$t("确定"),
                  cancelButtonText: this.$t("取消"),
                  type: "warning",
                }
              )
                .then(() => {
                  API_taskControl({
                    cmd: "3X11",
                    values: [this.taskId, this.execId],
                  }).then((res) => {
                    if (res.code == 200 && res.data.nerrcode == 0) {
                      this.$message({
                        type: "success",
                        message: this.$t("已恢复暂停任务!"),
                      });
                      this.status = "3";
                      this.addtaskVisible = false;
                      this.$emit("getDataList");
                    } else {
                      this.$message.error(this.$t("恢复暂停任务失败请重试"));
                    }
                  });
                })
                .catch(() => {
                  this.$message({
                    type: "info",
                    message: this.$t("已取消"),
                  });
                });
            }
          } else {
            this.$confirm(
              `${this.$t("确定暂停任务")}${this.drawerForm.name}?`,
              this.$t("提示"),
              {
                confirmButtonText: this.$t("确定"),
                cancelButtonText: this.$t("取消"),
                type: "warning",
              }
            )
              .then(() => {
                API_taskControl({
                  cmd: "3X12",
                  values: [this.taskId, this.execId],
                }).then((res) => {
                  if (res.code == 200 && res.data.nerrcode == 0) {
                    this.$message({
                      type: "success",
                      message: this.$t("任务已暂停"),
                    });
                    this.status = "4";
                    this.addtaskVisible = false;
                    this.$emit("getDataList");
                  } else {
                    this.$message.error(this.$t("暂停失败请重试"));
                  }
                });
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: this.$t("已取消"),
                });
              });
          }
          break;
        case "stop":
          this.$confirm(
            `${this.$t("确定终止任务")}${this.drawerForm.name}?`,
            this.$t("提示"),
            {
              confirmButtonText: this.$t("确定"),
              cancelButtonText: this.$t("取消"),
              type: "warning",
            }
          )
            .then(() => {
              API_taskControl({
                cmd: "3X13",
                values: [this.taskId, this.execId],
              }).then((res) => {
                if (res.code == 200 && res.data.nerrcode == 0) {
                  this.$emit("getDataList");
                  this.$message({
                    type: "success",
                    message: this.$t("任务已终止"),
                  });
                  this.status = "6";
                  this.addtaskVisible = false;
                } else {
                  this.$message.error(this.$t("终止失败请重试"));
                }
              });
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: this.$t("已取消"),
              });
            });
          break;
      }
    },
    /**任务模板列表 */
    getTemplateList() {
      API_TemplateList({}).then((res) => {
        if (res.code == 200) {
          if (res.rows.length > 0) {
            this.templateList = res.rows;
          } else {
            this.templateList = [];
          }
        }
      });
    },
    closeTaskModal() {
      this.addtaskVisible = false;
    },
    open(type, title, status, taskId, taskExecId) {
      this.type = type;
      this.title = title;
      this.taskExecId = taskExecId;
      this.addtaskVisible = true;
      this.getTemplateList();
      //新增
      if (this.type == "add") {
        this.resetDrawerForm();
        this.drawerBooArr.forEach((item) => {
          if (item.type == "immediate") {
            item.bool = true;
          } else {
            item.bool = false;
          }
        });
        this.drawActionOptions = [
          {
            value: "0",
            label: this.$t("无"),
          },
        ];
        this.drawerForm.overTimeLength = this.$t("即时任务无时长限制");
        this.drawerForm.overTimeActionType = "0";
        //预览
      } else {
        this.status = status;
        this.rowTaskId = taskId.toString();
        if (
          this.status == 1 ||
          this.status == 2 ||
          this.status == 3 ||
          this.status == 4
        ) {
          this.getManageInfo(taskId);
        } else {
        }
      }
      this.currentTaskTimer = setInterval(() => {
        this.getTaskInfo();
      }, 1000);
    },
    //选择模板
    changeTemplate(item) {
      this.drawerForm.name = item.name + this.insertTempName();
      this.$forceUpdate();
      this.templateId = item.id;
    },
    //修改任务类型
    changeType(e) {
      if (e == "immediate") {
        this.drawActionOptions = [
          {
            value: "0",
            label: this.$t("无"),
          },
        ];
        this.drawerForm.overTimeLength = "即时任务无时长限制";
        this.drawerForm.overTimeActionType = "0";
        this.drawerForm.tempType = "即时任务";
      } else if (e == "regular") {
        this.drawActionOptions = [
          {
            value: "1",
            label: this.$t("原地待命"),
          },
          {
            value: "2",
            label: this.$t("回充电桩"),
          },
          {
            value: "4",
            label: this.$t("前往停靠点"),
          },
        ];
        this.drawerForm.overTimeLength = "120";
        this.drawerForm.overTimeActionType = "";
      } else {
        this.drawerForm.overTimeLength = "120";
        this.drawerForm.overTimeActionType = "";
      }
      this.drawerBooArr.forEach((item) => {
        if (item.type == e) {
          item.bool = true;
        } else {
          item.bool = false;
        }
      });
    },
    /**获取本地时间： */
    insertTempName() {
      var now = new Date();
      var year = now.getFullYear();
      var month = now.getMonth();
      month = month + 1;
      var date = now.getDate();
      var hours = now.getHours();
      var minuts = now.getMinutes();
      var seconds = now.getSeconds();
      if (month < 10) {
        month = "0" + month;
      }
      if (date < 10) {
        date = "0" + date;
      }
      var time =
        year.toString() +
        month.toString() +
        date.toString() +
        hours.toString() +
        minuts.toString() +
        seconds.toString();
      return time;
    },
    /**重复频率 change */
    repeatRateUnitChange() {
      //处理月份
      this.monthsData = this.monthsData.map((item) => {
        return {
          label: item.label,
          isSelected: false,
        };
      });
      // 处理周
      this.weekData = this.weekData.map((item) => {
        return {
          label: item.label,
          isSelected: false,
        };
      });
    },
    /**选择快速设置 */
    chooseQuickSetting(index) {
      if (this.currentSetting != index) {
        this.currentSetting = ""; //清空数据
        this.currentSetting = index;
      }
      // 处理时间
      switch (index) {
        //本月
        case 0:
          this.drawerForm.quickStartDate = moment()
            .startOf("month")
            .format("YYYY-MM-DD HH:mm:ss");
          this.drawerForm.quickEndDate = moment()
            .endOf("month")
            .format("YYYY-MM-DD HH:mm:ss");
          break;
        // 本季度;
        case 1:
          this.drawerForm.quickStartDate = moment(
            moment().quarter(moment().quarter()).startOf("quarter").valueOf()
          ).format("YYYY-MM-DD HH:mm:ss");
          this.drawerForm.quickEndDate = moment(
            moment().quarter(moment().quarter()).endOf("quarter").valueOf()
          ).format("YYYY-MM-DD HH:mm:ss");
          break;
        // 本年
        case 2:
          this.drawerForm.quickStartDate = moment()
            .year(moment().year())
            .startOf("year")
            .format("YYYY-MM-DD HH:mm:ss")
            .valueOf();
          this.drawerForm.quickEndDate = moment()
            .year(moment().year())
            .endOf("year")
            .format("YYYY-MM-DD HH:mm:ss")
            .valueOf();
          break;
        // 未来30天
        case 3:
          this.drawerForm.quickStartDate = moment(new Date()).format(
            "YYYY-MM-DD HH:mm:ss"
          );
          this.drawerForm.quickEndDate = moment(new Date())
            .add(30, "days")
            .format("YYYY-MM-DD HH:mm:ss");
          break;
        // 未来90天
        case 4:
          this.drawerForm.quickStartDate = moment(new Date()).format(
            "YYYY-MM-DD HH:mm:ss"
          );
          this.drawerForm.quickEndDate = moment(new Date())
            .add(90, "days")
            .format("YYYY-MM-DD HH:mm:ss");
          break;
        // 未来365天
        case 5:
          this.drawerForm.quickStartDate = moment(new Date()).format(
            "YYYY-MM-DD HH:mm:ss"
          );
          this.drawerForm.quickEndDate = moment(new Date())
            .add(365, "days")
            .format("YYYY-MM-DD HH:mm:ss");
          break;
      }
    },
    /**选择 月 */
    monthClick(index, item) {
      this.monthActive = index;
      //然后通过这个属性判断是否选中点亮和取消
      item.isSelected = !item.isSelected;
    },
    /**选择 周 */
    weekClick(index, item) {
      this.weekActive = index;
      //然后通过这个属性判断是否选中点亮和取消
      item.isSelected = !item.isSelected;
    },
    /**抽屉取消 */
    drawerCancle() {
      this.addtaskVisible = false;
      this.taskVisible = false;
    },
    /**弹框内部取消 */
    taskDialogCancle() {
      this.taskVisible = false;
    },
    /**弹框内部确认 */
    dialogConfirm(radioVal) {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      if (radioVal == 1) {
        //暂停当前任务
        API_taskControl({
          cmd: "3X12",
          values: [this.taskId, this.execId],
        })
          .then((res) => {
            if (res.code == 200 && res.data.nerrcode == 0) {
              this.$message({
                type: "success",
                message: this.$t("任务已暂停"),
              });
              const immediateLoading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
                background: "rgba(0, 0, 0, 0.7)",
              });
              let immediatePara = {
                id: this.templateId,
                name: this.drawerForm.name,
                agingTime: this.drawerForm.agingTime,
              };
              API_immediate(immediatePara)
                .then((res) => {
                  if (res.code == 200) {
                    this.drawerVisible = false;
                    this.$emit("getDataList");
                    this.$message.success(this.$t("立即执行操作成功"));
                    this.addtaskVisible = false;
                  }
                })
                .finally(() => {
                  immediateLoading.close();
                  this.addtaskVisible = false;
                });
            } else {
              this.$message.error(this.$t("暂停失败请重试"));
            }
          })
          .finally(() => {
            loading.close();
            this.taskVisible = false;
            this.drawerVisible = false;
            this.addtaskVisible = false;
          });
      } else if (radioVal == 2) {
        //终止当前任务
        API_taskControl({
          cmd: "3X13",
          values: [this.taskId, this.execId],
        })
          .then((res) => {
            if (res.code == 200 && res.data.nerrcode == 0) {
              this.$message({
                type: "success",
                message: this.$t("任务已终止"),
              });
              //执行当前任务
              const immediateLoading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
                background: "rgba(0, 0, 0, 0.7)",
              });
              let params = {
                id: this.templateId,
                name: this.drawerForm.name,
                agingTime: this.drawerForm.agingTime,
              };
              API_immediate(params)
                .then((res) => {
                  if (res.code == 200) {
                    this.drawerVisible = false;
                    this.$emit("getDataList");
                    this.$message.success(this.$t("立即执行操作成功"));
                    this.addtaskVisible = false;
                  }
                })
                .finally(() => {
                  immediateLoading.close();
                  this.addtaskVisible = false;
                });
            } else {
              this.$message.error(this.$t("暂停失败请重试"));
            }
          })
          .finally(() => {
            loading.close();
            this.taskVisible = false;
            this.drawerVisible = false;
            this.addtaskVisible = false;
          });
      } else {
        //继续当前任务
      }
    },
    /**根据id查询任务信息 */
    getManageInfo(id) {
      API_GetTaskDetail(id).then((res) => {
        if (res.code == 200) {
          this.detailInfos = res.data;
          this.drawerForm.templateName = this.detailInfos.tempId;
          this.drawerForm.name = this.detailInfos.taskName;
          switch (this.detailInfos.taskType) {
            case 1:
              //即使任务
              this.drawerBooArr.forEach((item) => {
                if (item.type == "immediate") {
                  item.bool = true;
                } else {
                  item.bool = false;
                }
              });
              this.drawerForm.tempType = this.$t("即时任务");
              this.drawerForm.overTimeLength = this.$t("即时任务无时长限制");
              this.drawActionOptions = [
                {
                  value: "0",
                  label: this.$t("无"),
                },
              ];
              this.drawerForm.overTimeActionType = "0";
              this.drawerForm.agingTime = this.detailInfos.agingTime; //超时上限
              break;
            case 2:
              //定时任务
              this.drawerForm.tempType = "定期任务";
              this.drawerBooArr.forEach((item) => {
                if (item.type == "regular") {
                  item.bool = true;
                } else {
                  item.bool = false;
                }
              });
              this.drawerForm.overTimeLength = this.detailInfos.overTimeLength; //超时时长
              this.drawerForm.overTimeActionType =
                this.detailInfos.overTimeActionType + ""; //超时动作
              this.$set(
                this.drawerForm,
                "stopPointOne",
                this.detailInfos.stopPoint
              ); //停靠点位置
              this.drawActionOptions = [
                {
                  value: "1",
                  label: this.$t("原地待命"),
                },
                {
                  value: "2",
                  label: this.$t("回充电桩"),
                },
                {
                  value: "4",
                  label: this.$t("前往停靠点"),
                },
              ];
              this.drawerForm.regularStartTime = this.detailInfos.startTime; //启动时间
              this.drawerForm.agingTime = this.detailInfos.agingTime; //超时上限
              break;
            case 3:
              //周期任务
              this.drawerForm.tempType = this.$t("周期任务");
              this.drawerBooArr.forEach((item) => {
                if (item.type == "cycle") {
                  item.bool = true;
                } else {
                  item.bool = false;
                }
              });
              this.drawerForm.cycleType = this.detailInfos.cycleType + ""; //周期类型
              this.drawerForm.startTime = this.detailInfos.startTime; //开始日期
              this.drawerForm.endTime = this.detailInfos.endTime; //结束日期
              this.drawerForm.executeTimePre = JSON.parse(
                this.detailInfos.executeTime
              ).h; //启动时间-小时
              this.drawerForm.executeTimeNext = JSON.parse(
                this.detailInfos.executeTime
              ).m; //启动时间-分钟
              this.drawerForm.repeatRate = this.detailInfos.repeatRate; //重复频率
              this.drawerForm.repeatRateUnit = this.detailInfos.repeatRateUnit; //重复频率单位
              this.drawerForm.overTimeLength = this.detailInfos.overTimeLength; //超时时长
              this.drawerForm.overTimeActionType =
                this.detailInfos.overTimeActionType + ""; //超时动作
              this.$set(
                this.drawerForm,
                "stopPoint",
                this.detailInfos.stopPoint
              ); //停靠点
              this.drawerForm.agingTime = this.detailInfos.agingTime; //超时上限
              this.drawerForm.trainingSampleGather =
                this.detailInfos.trainingSampleGather + ""; //训练样本
              this.drawerForm.trainingSampleCount =
                this.detailInfos.trainingSampleCount; //云台单向转动次数
              this.drawerForm.trainingSampleAngle =
                this.detailInfos.trainingSampleAngle; //云台转向角度间隔
              break;
          }
          // }
          // });
        }
      });
    },
    /**重置drawer表单内容 */
    resetDrawerForm() {
      this.drawerForm = {
        name: "", //任务名称
        templateName: "", //任务名称
        tempType: this.$t("即时任务"), //任务类型
        agingTime: 0, //超时上限
        regularStartTime: "", //定期执行开始时间
        cycleType: "1",
        validType: "2", //生效时长
        hurrySetting: "", //快速设置
        quickStartDate: "", //快速设置-开始日期
        quickEndDate: "", //快速设置-结束日期
        // 执行配置
        repeatRate: "3", //重复频率
        repeatRateUnit: "2", //重复频率单位
        //执行时间
        month: "", //循环monthsData获取isSelet为true
        week: "", //同上
        seconds: "",
        h: "",
        m: "",
        s: "",
        trainingSampleGather: "1", //是否采集训练样本
        trainingSampleCount: "", //云台转动次数
        trainingSampleAngle: "", //云台转动间隔
        //常规  生效时段
        startTime: "", //开始日期
        endTime: "", //结束日期
        overTimeLength: "", //超时时长
        overTimeActionType: "", //超时动作
        executeTimePre: 8, //启动时间 前
        executeTimeNext: 0, //启动时间 后
      };
    },
    /**保存 btn */
    submitBtn() {
      this.$refs["drawerRef"].validate((valid) => {
        if (valid) {
          let performType = [];
          performType = this.drawerBooArr.find((item) => {
            return item.bool == true;
          }).type;
          switch (performType) {
            //立即执行
            case "immediate":
              // 判断是否有正在执行的任务
              if (this.taskId != -1) {
                //有 展示弹框
                this.taskVisible = true;
              } else {
                const immediateLoading = this.$loading({
                  lock: true,
                  text: "Loading",
                  spinner: "el-icon-loading",
                  background: "rgba(0, 0, 0, 0.7)",
                });
                let immediatePara = {
                  id: this.templateId,
                  name: this.drawerForm.name,
                  agingTime: this.drawerForm.agingTime,
                };
                API_immediate(immediatePara)
                  .then((res) => {
                    if (res.code == 200) {
                      this.drawerVisible = false;
                      this.$emit("getDataList");

                      this.$message.success(this.$t("立即执行操作成功"));
                      this.addtaskVisible = false;
                    }
                  })
                  .finally(() => {
                    immediateLoading.close();
                    this.addtaskVisible = false;
                  });
              }
              break;
            //定期执行
            case "regular":
              const regularLoading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
                background: "rgba(0, 0, 0, 0.7)",
              });
              let regularPara = {
                id: this.templateId,
                name: this.drawerForm.name,
                startTime: this.drawerForm.regularStartTime,
                agingTime: this.drawerForm.agingTime,
                overTimeLength: this.drawerForm.overTimeLength,
                overTimeActionType: this.drawerForm.overTimeActionType,
                stopPoint: this.drawerForm.stopPoint,
              };
              API_regular(regularPara)
                .then((res) => {
                  if (res.code == 200) {
                    this.drawerVisible = false;
                    this.$emit("getDataList");

                    this.$message.success(this.$t("定期执行操作成功"));
                    this.addtaskVisible = false;
                  }
                })
                .finally(() => {
                  regularLoading.close();
                  this.addtaskVisible = false;
                });
              break;
            //周期执行
            case "cycle":
              const cycleLoading = this.$loading({
                lock: true,
                text: "Loading",
                spinner: "el-icon-loading",
                background: "rgba(0, 0, 0, 0.7)",
              });
              let cyclePara = {
                id: this.templateId,
                name: this.drawerForm.name,
                startTime: moment(this.drawerForm.startTime).format(
                  "YYYY-MM-DD HH:mm:ss"
                ),
                endTime: moment(this.drawerForm.endTime).format(
                  "YYYY-MM-DD HH:mm:ss"
                ),
                executeTime: JSON.stringify({
                  h: this.drawerForm.executeTimePre,
                  m: this.drawerForm.executeTimeNext,
                }),
                repeatRate: this.drawerForm.repeatRate,
                repeatRateUnit: this.drawerForm.repeatRateUnit,
                overTimeLength: this.drawerForm.overTimeLength,
                overTimeActionType: this.drawerForm.overTimeActionType,
                agingTime: this.drawerForm.agingTime,
                stopPoint: this.drawerForm.stopPoint,
                trainingSampleGather: this.drawerForm.trainingSampleGather,
                trainingSampleCount: this.drawerForm.trainingSampleCount,
                trainingSampleAngle: this.drawerForm.trainingSampleAngle,
                validType: "2",
                cycleType: "1",
              };
              API_periodic(cyclePara)
                .then((res) => {
                  if (res.code == 200) {
                    this.drawerVisible = false;
                    this.$emit("getDataList");
                    this.$message.success(this.$t("周期执行操作成功"));
                    this.addtaskVisible = false;
                  }
                })
                .finally(() => {
                  cycleLoading.close();
                  this.addtaskVisible = false;
                });
              break;
          }
        }
      });
    },
  },
  beforeDestroy() {
    clearInterval(this.currentTaskTimer);
    this.currentTaskTimer = null;
  },
};
</script>
<style lang="scss" scoped>
.draw-content-explain {
  padding: 12px 0 12px 16px;
  font-size: 14px;
  background-color: rgba(255, 173, 48, 0.06);
  div {
    color: #ffad30;
  }
}
::v-deep {
  .el-input-number__increase,
  .el-input-number__decrease {
    background: transparent;
  }
  .el-icon-arrow-down:before,
  .el-icon-arrow-up:before {
    color: #fff;
  }
}
::v-deep {
  .el-date-editor--time {
    margin-left: 20px;
  }
}
//生效时段
.model,
.config,
.algorith {
  margin-bottom: 10px;
  padding: 15px 24px 10px;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.06);
  .model-title {
    font-size: 14px;
    font-family: SourceHanSansSC-Bold, SourceHanSansSC;
    font-weight: bold;
    color: #ffffff;
    line-height: 16px;
  }
  label {
    margin-left: 5px;
    color: #fff;
  }
}
.cycle-config {
  display: flex;
  justify-content: space-between;
  font-weight: bold;
  color: #ffffff;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(219, 255, 251, 0.14);
  .chang-btn {
    display: flex;
    div {
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 8px;
      height: 24px;
      line-height: 24px;
      font-size: 14px;
      line-height: none !important;
    }
    div:nth-child(1) {
      background-color: rgba(0, 209, 255, 0.2);
      border-radius: 2px 0px 0px 2px;
      border: 1px solid #00d1ff;
    }
    div:nth-child(2) {
      background-color: rgba(219, 255, 251, 0.2);
      border-radius: 2px 0px 0px 2px;
      border: 1px solid #dbfffb;
      border-left: 0;
    }
  }
}
.drawer-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  div:nth-child(2) {
    margin-left: 16px;
  }
}
</style>
